﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO.Model;
using DAO.Bussiness.Repository;

namespace Restaurante
{
    public partial class cocina : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblError.Text = "";
            HideColumns( gvCocina);
        }

        protected void btnAgregar_Click(object sender, EventArgs e)
        {
            Comanda_Detalle cd = new Comanda_Detalle();
            ComandaDetalleRepository cdr = new ComandaDetalleRepository();

            try{
                if (txbPlato.Text == "") {
                    lblError.Text = "Debe seleccionar una comanda !!!.";
                    return;
                }
                Int32 nroDet = Convert.ToInt32(txtDetalle.Text);
                cd = cdr.GetBy(u => u.Id_Detalle.Equals(nroDet)).Single();

                cd.Id_Estado = Convert.ToInt32(ddlEstado.SelectedItem.Value);

                cdr.Update(cd);
                cdr.Save();
                Response.Redirect("cocina.aspx");
            }catch (Exception ex){
            
            }

        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("home.aspx");
        }

        protected void gvCocina_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = null;
            row = gvCocina.SelectedRow;
            String plato = row.Cells[2].Text;
            String menu = row.Cells[5].Text;
            txtDetalle.Text = row.Cells[8].Text;

            if (plato == "" || plato == "&nbsp;")
            {
                txbPlato.Text = menu;
            }
            else {
                txbPlato.Text = plato;
            }
        }

        private void HideColumns(GridView grdView)
        {
            if (!(grdView.HeaderRow == null))
            {
                grdView.HeaderRow.Cells[1].Visible = false;
                grdView.HeaderRow.Cells[grdView.Columns.Count - 1].Visible = false;
                foreach (GridViewRow row in grdView.Rows)
                {
                    row.Cells[1].Visible = false;
                    row.Cells[grdView.Columns.Count - 1].Visible = false;
                }
            }
        }


    }
}